package com.atguigu.srb.core.controller.api;

import com.atguigu.srb.common.result.Result;
import com.atguigu.srb.core.pojo.entity.Lend;
import com.atguigu.srb.core.service.LendService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.time.Year;
import java.util.List;
import java.util.Map;

/**
 * @author lsyandwh
 * @create 2022-12-17 8:50
 */
@Api(tags = "标的")
@RestController
@RequestMapping("/api/core/lend")
public class ApiLendController {

    @Autowired
    private LendService lendService;

    @GetMapping("/list")
    public Result listLend(){
        List<Lend> list = lendService.lendList();

        return Result.ok().data("lendList",list);
    }

    @GetMapping("/show/{id}")
    public Result show(@PathVariable Long id){

        Map<String, Object> show = lendService.show(id);

        return Result.ok().data("lendDetail",show);
    }

    @GetMapping("/getInterestCount/{invest}/{yearRate}/{totalmonth}/{returnMethod}")
    public Result getInterestCount(@PathVariable("invest")BigDecimal invest,
                                   @PathVariable("yearRate") BigDecimal yearRate,
                                   @PathVariable("totalmonth")Integer totalmonth,
                                   @PathVariable("returnMethod")Integer returnMethod){

        BigDecimal interestCount = lendService.getInterestCount(invest, yearRate, totalmonth, returnMethod);

        return Result.ok().data("interestCount",interestCount);
    }
}
